import sys
import os

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'..','modules')))
import mods


def index(req):
	web = mods.Web(req)
	web.Header()


	web.Write("""
		<h2>Welcome to the SA Open Database</h2>
		<p>The idea of this project is to create a place where people can collaborate and create a database that
		can easily be imported in your own app. We are currently busy to create a hierarchical list of regions in South Africa.
		</p>
		""")


	dbConnection = mods.GetDBConnection()
	cursor = dbConnection.cursor()

	locationCount = 0
	cursor.execute("""SELECT COUNT(1) FROM locations""")
	if cursor.rowcount:
		(locationCount, ) = cursor.fetchone()

	web.Write("""<br /><table class="data">""")
	web.Write("""<tr><th style="text-align: right;">Location count</th><td style="text-align: right;">%s</td>""" % (locationCount))
	web.Write("""</table><br />""")


	web.Footer()


